package cn.ymatrix.WeChat.groupMessage;

import java.sql.*;
import java.util.HashMap;
import java.util.Map;

public class DBAlarmDataUrils {

    static String url = "jdbc:postgresql://172.16.172.151:5433/postgres";
    static String username = "mxadmin";
    static String password = "mxadmin";

    public static Map<Object, Object> dbAarmResultSet() throws SQLException {
        Map<Object, Object> alarm_results = new HashMap<Object, Object>();
        String results = "";
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            Class.forName("org.postgresql.Driver");
            conn = DriverManager.getConnection(url, username, password);
            // System.out.println("Database connected");
            stmt = conn.createStatement();
            rs = stmt.executeQuery("select device_sn from device_alarm_parameter where device_sn = 'DB80.201' and status = 't'");
            while (rs.next()) {
                results = rs.getString(1);
                //  System.out.println(rs.getString(1));
            }
            rs = stmt.executeQuery("select alarm_time_out as alarm_time,alarm_count_out as alarm_count from function_device_alarm('" + results + "')");
            while (rs.next()) {
                alarm_results.put("alarm_time", rs.getString("alarm_time"));
                alarm_results.put("alarm_count", rs.getString("alarm_count"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            rs.close();
            stmt.close();
            conn.close();
        }
        return alarm_results;
    }


}
